function calliope()

dvh.hf=figure(1001);
set(dvh.hf,'name','calliope','numberTitle','off');
clf

mon_pos=get(0,'MonitorPositions');
set(dvh.hf,'color','k','position', [mon_pos(1,1)+round(0.85*(mon_pos(1,3)-mon_pos(1,1))) 150 250 350],'menubar','none');
define_paths_calliope(dvh);


cn_str = 'PROVIDER=SQLOLEDB; Data Source=PIA1; initial catalog=ExpLog; User ID=explog_user; password=Keller123';
DB = adodb_connect(cn_str, 240);
sql = ['SELECT Stacks.stackid, Stacks.expid, Stacks.comment, Experiments.siteid, Experiments.analysiscode,',...
    'Sites.animalid, Sites.project, Animals.pi FROM Stacks INNER JOIN Experiments ON Stacks.expid=Experiments.expid ' ...
    'INNER JOIN Sites ON Experiments.siteid=Sites.siteid INNER JOIN Animals ON Sites.AnimalID=Animals.AnimalID ORDER BY Stacks.stackid'];
ExpLog = adodb_query(DB, sql);
DB.release;
assignin('base','ExpLog', ExpLog);

adata_dir='\\argon.fmi.ch\keller.g\AData\';
tmp = dir(adata_dir);
if isempty(tmp)
    !start /max \\argon.fmi.ch\keller.g
    disp('Please log into argon and start calliope again.')
    close(dhv.hf);
    return
end

assignin('base','adata_dir',adata_dir);
[adata_list]=list_all_adata_files(adata_dir);

global adata_list_num;
adata_list_num=zeros(1,length(adata_list));
for znd=1:length(adata_list)
    adata_list_num(znd)=str2num(adata_list{znd});
end

lb1=0.05;
lb2=0.4;
lb3=0.725;
wf=0.9;
w0=0.625;
w1=0.325;
w2=0.275;
w3=0.225;
h1=0.06;
h2=0.015;

h_ind=13;
dvh.title_string=uicontrol('style','edit',...
    'string','nothing loaded',...
    'value',1,...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 wf h1],...
    'BackgroundColor',[1 1 1]*0,...
    'ForegroundColor','r');

h_ind=12;
dvh.user_select=uicontrol('style','popupmenu',...
    'string','-',...
    'value',1,...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 w0 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g');

h_ind=11;
dvh.project_select=uicontrol('style','popupmenu',...
    'string','-',...
    'value',1,...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 w0 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g');

h_ind=10;
dvh.mouse_select=uicontrol('style','popupmenu',...
    'string','-',...
    'value',1,...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 w0 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g');

h_ind=9;
dvh.exp_select=uicontrol('style','popupmenu',...
    'string','-',...
    'value',1,...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 w0 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g');


h_ind=8;
dvh.load=uicontrol('style','pushbutton',...
    'string','load',...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 w1 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left');

h_ind=7;
dvh.select_rois=uicontrol('style','pushbutton',...
    'string','select ROIs',...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 w1 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left');

h_ind=6;
dvh.save_adata=uicontrol('style','pushbutton',...
    'string','save A-data',...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 w1 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left',...
    'callback',@save_Adata_callback);
%     'evalin(''base'',''save_adata(adata_dir,ROIs,bv,np,template,dx,dy,aux_files,fnames,nbr_frames,mouse_id,userID,act_map)'')');
%     'evalin(''base'',''save_adata(adata_dir,ROIs,bv,np,template,dx,dy,aux_files,fnames,nbr_frames,mouse_id,date_id,act_map)'');');
h_ind=5;
dvh.plot_data=uicontrol('style','pushbutton',...
    'string','plot it',...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 w1 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left',...
    'callback',@plot_callback);

h_ind=8;
dvh.preview_adata=uicontrol('style','pushbutton',...
    'string','get adata',...
    'units','normalized',...
    'position',[lb2 (h1+h2)*h_ind-h1 w2 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left',...
    'callback',{@preview_adata_callback,ExpLog,dvh,adata_dir});

h_ind=7;
dvh.register_entire_dir=uicontrol('style','pushbutton',...
    'string','reg. dir',...
    'units','normalized',...
    'position',[lb2 (h1+h2)*h_ind-h1 w2 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left',...
    'callback',{@register_entire_dir_callback,ExpLog,dvh,adata_dir});

h_ind=6;
dvh.calc_act=uicontrol('style','pushbutton',...
    'string','calc act',...
    'units','normalized',...
    'position',[lb2 (h1+h2)*h_ind-h1 w2 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left',...
    'callback',{@calcROIact,ExpLog,dvh,adata_dir});

h_ind=5;
dvh.view_tif=uicontrol('style','pushbutton',...
    'string','data expl.',...
    'units','normalized',...
    'position',[lb2 (h1+h2)*h_ind-h1 w2 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left',...
    'callback',@view_tiff_callback);

% h_ind=4;
% dvh.view_eye=uicontrol('style','pushbutton',...
%     'string','view eye',...
%     'units','normalized',...
%     'position',[lb3 (h1+h2)*h_ind-h1 w2 h1],...
%     'BackgroundColor',[1 1 1]*0.1,...
%     'ForegroundColor','g',...
%     'HorizontalAlignment','left',...
%     'callback','evalin(''base'',''view_eye_stack(idata,imeta_data)'');');


h_ind=5;
dvh.load_meta=uicontrol('style','pushbutton',...
    'string','load meta',...
    'units','normalized',...
    'position',[lb3 (h1+h2)*h_ind-h1 w2 h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left');


h_ind=8;
dvh.ftypes=uicontrol('style','listbox',...
    'string','-',...
    'units','normalized',...
    'position',[lb3 (h1+h2)*h_ind-h1 w3 6*h1],...
    'BackgroundColor',[1 1 1]*0.1,...
    'ForegroundColor','g',...
    'HorizontalAlignment','left',...
    'Min',1,'Max',10);
% uicontrol('style','frame',...
%     'units','normalized',...
%     'position',[lb3+0.625*w3 (h1+h2)*h_ind-h1 w3 6*h1],...
%     'BackgroundColor',[1 1 1]*0,...
%     'ForegroundColor',[1 1 1]*0);

h_ind=1;
dvh.comments=uicontrol('style','listbox',...
    'string','-',...
    'value',[],...
    'units','normalized',...
    'position',[lb1 (h1+h2)*h_ind-h1 wf 5*h1-h2],...
    'BackgroundColor',[1 1 1]*0,...
    'ForegroundColor',[0 0.8 0],...
    'Max',10,...
    'SelectionHighlight','off',...
    'HorizontalAlignment','left');

[userIDs,~,ExpStrs,~,mouseIDs,~,projectIDs,ftypes,comments]=get_menu_data(ExpLog,dvh,adata_dir);
set(dvh.user_select,'string',userIDs,'value',1);
set(dvh.project_select,'string',projectIDs,'value',1);
set(dvh.mouse_select,'string',mouseIDs,'value',1);
set(dvh.exp_select,'string',ExpStrs,'value',1);
set(dvh.ftypes,'string',ftypes{get(dvh.exp_select,'value')})
set(dvh.comments,'string',comments{get(dvh.exp_select,'value')});

set(dvh.user_select,'callback',{@user_select_callback,dvh,ExpLog,adata_dir});
set(dvh.project_select,'callback',{@project_select_callback,dvh,ExpLog,adata_dir});
set(dvh.mouse_select,'callback',{@mouse_select_callback,dvh,ExpLog,adata_dir});
set(dvh.exp_select,'callback',{@exp_select_callback,dvh,ExpLog,adata_dir});
set(dvh.select_rois,'callback',{@select_rois_callback,ExpLog,dvh,adata_dir});
set(dvh.load,'callback',{@load_callback,ExpLog,dvh,adata_dir});
set(dvh.load_meta,'callback',{@load_meta_callback,dvh});
set(dvh.hf,'HandleVisibility','off','IntegerHandle','on')

function user_select_callback(e,h,dvh,ExpLog,adata_dir)
set(dvh.project_select,'value',1);
set(dvh.mouse_select,'value',1);
[~,~,~,~,~,~,projectIDs]=get_menu_data(ExpLog,dvh,adata_dir);
set(dvh.project_select,'string',projectIDs);
project_select_callback(e,h,dvh,ExpLog,adata_dir)

function project_select_callback(e,h,dvh,ExpLog,adata_dir)
set(dvh.mouse_select,'value',1);
[~,~,~,~,mouseIDs,~,projectIDs]=get_menu_data(ExpLog,dvh,adata_dir);
set(dvh.mouse_select,'value',1,'string',mouseIDs);
proj=projectIDs{get(dvh.project_select,'value')};
projDefaults=set_projDefaults(proj);
set(dvh.ftypes,'UserData',projDefaults);
mouse_select_callback(e,h,dvh,ExpLog,adata_dir)

function mouse_select_callback(e,h,dvh,ExpLog,adata_dir)
set(dvh.exp_select,'value',1);
[~,~,ExpStrs,~]=get_menu_data(ExpLog,dvh,adata_dir);
set(dvh.exp_select,'string',ExpStrs);
exp_select_callback(e,h,dvh,ExpLog,adata_dir)

function exp_select_callback(e,h,dvh,ExpLog,adata_dir)
[~,~,~,~,~,~,~,ftypes,comments]=get_menu_data(ExpLog,dvh,adata_dir);
projDefaults=get(dvh.ftypes,'UserData');
curr_ftypes=ftypes{get(dvh.exp_select,'value')};
[~,floc]=intersect(curr_ftypes,projDefaults);
set(dvh.ftypes,'string',ftypes{get(dvh.exp_select,'value')})
set(dvh.ftypes,'value',floc)
set(dvh.comments,'string',comments{get(dvh.exp_select,'value')});

function load_callback(e,h,ExpLog,dvh,adata_dir)
% userIDs=get(dvh.user_select,'string');
% userID=userIDs{get(dvh.user_select,'value')};
[~,ExpIDs,~,~]=get_menu_data(ExpLog,dvh,adata_dir);
set(dvh.title_string,'string',['loaded Exp ' num2str(ExpIDs(get(dvh.exp_select,'value'))) ' - ' datestr(now,13)]);
disp(['Loading Exp --- ' num2str(ExpIDs(get(dvh.exp_select,'value'))) ' --- ' datestr(now)])
disp('clearing data to prevent mismatch!');
evalin('base','clear data;');
ftypes=get(dvh.ftypes,'string');
load_exp(ExpIDs(get(dvh.exp_select,'value')),adata_dir,dvh,ftypes(get(dvh.ftypes,'value')));

function load_meta_callback(e,h,dvh)
[fname,fpath] = uigetfile('\\argon.fmi.ch\keller.g\AData\_metaData');
set(dvh.title_string,'string',['loaded meta ' fname ' - ' datestr(now,13)]);
disp(['------ Now loading meta file ' fname ' ------']);
evalin('base',['load(''' fpath fname ''');']);
disp('------ Done loading ------')

function select_rois_callback(e,h,ExpLog,dvh,adata_dir)

template=evalin('base','template');

if isa(template,'cell')
    z_plane=input(['There are ' num2str(length(template)) ' z-planes' '. Select z-plane: ']);
    assignin('base','z_plane',z_plane);
else
    z_plane=0;
    assignin('base','z_plane',z_plane);
end

[~,ExpIDs,~,same_site_as_ID,~,ExpGroup]=get_menu_data(ExpLog,dvh,adata_dir);
assignin('base','ExpGroup',ExpGroup);
[ofile_ID,omouse_ID,ouser_ID]=find_adata_file(same_site_as_ID(get(dvh.exp_select,'value')),adata_dir);
[file_ID,mouse_ID,user_ID]=find_adata_file(ExpIDs(get(dvh.exp_select,'value')),adata_dir);
curr=load([adata_dir user_ID '\' mouse_ID '\' file_ID],'template','ROIs','ROItrans','bv','np');

if z_plane==0
    if isempty(ofile_ID)
        disp('first exp of this site not registered yet - will improvise')
        evalin('base','find_cells_gui(template,ROIs,[0 0 0],act_map)');
    else
        orig=load([adata_dir ouser_ID '\' omouse_ID '\' ofile_ID],'template','ROIs','ROItrans','bv','np');
        try
            orig.ROIs=rmfield(orig.ROIs,'activity');
            orig.bv=rmfield(orig.bv,'activity');
            orig.np=rmfield(orig.np,'activity');
        end
        if ~isfield(orig,'ROItrans')
            orig.ROItrans=zeros(3,1);
        end
        assignin('base','orig_template',orig.template);
        load_curr=0;
        if length(curr.ROIs)>1
            disp('ROIs were already registered for this Exp')
            load_curr=input('Use saved ROIs (1) or choose new (0)? ');
            if load_curr
                if strcmp(ofile_ID,file_ID)
                    evalin('base','find_cells_gui(template,ROIs,ROItrans,act_map,orig_template)');
                else
                    disp('This file ID differs from the saved one')
                    load_curr_nf=input('Use ROIs saved in this file (1) or the orig file (0) ROIs? ');
                    if load_curr_nf
                        evalin('base','find_cells_gui(template,ROIs,ROItrans,act_map,orig_template)');
                    else
                        load_curr=0;
                    end
                end
            end
        end
        if ~load_curr
            disp('ROIs were not registered for this Exp - using main ROIs')
            assignin('base','bv',orig.bv);
            assignin('base','np',orig.np);
            assignin('base','ROIs',orig.ROIs);
            assignin('base','ROItrans',orig.ROItrans);
            evalin('base','find_cells_gui(template,ROIs,ROItrans,act_map,orig_template)');
        end
    end
else
    if isempty(ofile_ID)
        disp('first exp of this site not registered yet - will improvise')
        evalin('base','find_cells_gui(template,ROIs,[0 0 0],act_map)');
        try
            orig.ROIs=rmfield(orig.ROIs,'activity');
            orig.bv=rmfield(orig.bv,'activity');
            orig.np=rmfield(orig.np,'activity');
        end
        if ~isfield(orig,'ROItrans')
            orig.ROItrans=zeros(3,1);
        end
    else
        orig=load([adata_dir ouser_ID '\' omouse_ID '\' ofile_ID],'template','ROIs','ROItrans','bv','np');
        try
            orig.ROIs{z_plane}=rmfield(orig.ROIs{z_plane},'activity');
            orig.bv{z_plane}=rmfield(orig.bv{z_plane},'activity');
            orig.np{z_plane}=rmfield(orig.np{z_plane},'activity');
        end
        if ~isfield(orig,'ROItrans')
            orig.ROItrans=cell(1,length(orig.ROIs));
            for rnd=1:length(orig.ROIs)
                orig.ROItrans{rnd}=zeros(3,1);
            end
        end
    end
    assignin('base','orig_template',orig.template);
    assignin('base','z_plane',z_plane);
    if length(curr.ROIs{z_plane})>1
        disp('ROIs were already selected for this Exp')
        load_curr=input('Use saved ROIs (1) or choose new (0)? ');
        if load_curr
            if strcmp(ofile_ID,file_ID)
                evalin('base','find_cells_gui(template{z_plane},ROIs{z_plane},ROItrans{z_plane},act_map{z_plane},orig_template{z_plane})');
            else
                load_curr_nf=input(['Use ROIs saved in this file (1) or the orig file (0) ROIs? ']);
                if load_curr_nf
                    evalin('base','find_cells_gui(template{z_plane},ROIs{z_plane},ROItrans{z_plane},act_map{z_plane},orig_template{z_plane})');
                else
                    load_curr=0;
                end
            end
        else
            orig.ROIs{z_plane}=struct;
        end
    else
        load_curr=0;
    end
    if load_curr==0
        disp('ROIs were not registered for this Exp - using main ROIs')
        assignin('base','orig_bv',orig.bv{z_plane});
        evalin('base','bv{z_plane}=orig_bv;')
        assignin('base','orig_np',orig.np{z_plane});
        evalin('base','np{z_plane}=orig_np;')
        assignin('base','orig_ROIs',orig.ROIs{z_plane});
        evalin('base','ROIs{z_plane}=orig_ROIs;')
        assignin('base','orig_ROItrans',orig.ROItrans{z_plane});
        evalin('base','ROItrans{z_plane}=orig_ROItrans;')
        evalin('base','find_cells_gui(template{z_plane},ROIs{z_plane},ROItrans{z_plane},act_map{z_plane},orig_template{z_plane})');
    end
end

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function save_Adata_callback(e,h)
evalin('base','save_adata(adata_dir,ROIs,bv,np,template,dx,dy,aux_files,fnames,nbr_frames,mouse_id,userID,act_map)')

function view_tiff_callback(e,h)
dx=evalin('base','dx');
if isa(dx,'cell')
    view_z_plane=input(['There are ' num2str(length(dx)) ' z-planes' '. Select z-plane: ']);
    evalin('base',['view_tiff_stack(data{' num2str(view_z_plane) '})']);
else
    evalin('base','view_tiff_stack(data)');
end

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %

function plot_callback(e,h)
if ishandle(1003)
    close(1003)
end
template=evalin('base','template');

if isa(template,'cell')
    z_plane=input(['There are ' num2str(length(template)) ' z-planes' '. Select z-plane: ']);
    assignin('base','z_plane',z_plane);
else
    z_plane=0;
    assignin('base','z_plane',z_plane);
end
if z_plane>0
    evalin('base',['plot_activity_gen(ROIs{' num2str(z_plane) '},bv{' num2str(z_plane) '},np{' num2str(z_plane) '},template{' num2str(z_plane) '},''plot_aux_data'');']);
else
    evalin('base','plot_activity_gen(ROIs,bv,np,template,''plot_aux_data'');');
end

function register_entire_dir_callback(e,h,ExpLog,dvh,adata_dir)
answer = questdlg('Do you want to register all data? This takes roughly 10 min per exp', ...
    'Batch registration','All project experiments','Only this animal','Cancel','Cancel');

switch answer
    case 'All project experiments'
        ExpIDs = get_proj_ExpIDs(ExpLog,dvh);
    case 'Only this animal'
        [~,ExpIDs,~,~] = get_menu_data(ExpLog,dvh,adata_dir);
    case 'Cancel'
        return
end
disp('##############################################');
disp('Batch registering of data in current directory');
disp('##############################################');
for ind=1:length(ExpIDs)
    %         try
    disp('************************');
    disp(['Now registering exp ' num2str(ExpIDs(ind))]);
    disp('************************');
    evalin('base','clear data');
    register_exp(ExpIDs(ind),adata_dir,dvh)
    %         catch
    %             disp(['There was an ERROR with Exp ' num2str(ExpIDs(ind))])
    %         end
end

function calcROIact(e,h,ExpLog,dvh,adata_dir)

answer = questdlg('Do you want to calculate activity for all data?', ...
    'Batch registration','All my experiments','Only this animal','Cancel','Cancel');

switch answer
    case 'All my experiments'
        ExpIDs = get_proj_ExpIDs(ExpLog,dvh);
    case 'Only this animal'
        [~,ExpIDs,~,~] = get_menu_data(ExpLog,dvh,adata_dir);
    case 'Cancel'
        return
end

calc_rois=0;
for ind=1:length(ExpIDs)
    display(['Now evaluating experiment ' num2str(ExpIDs(ind)) '*******************'])
    [adata_file,mouse_id,userID]=find_adata_file(ExpIDs(ind),adata_dir);
    if isempty(adata_file)
        calc_rois=0;
        display('Found no Adata file')
    elseif strcmp(adata_file(1:9),'mean_data')
        calc_rois=0;
        display('this is a Z stack')
    else
        matobj=matfile([adata_dir '\' userID '\' mouse_id '\' adata_file]);
        if iscell(matobj.bv)
            tempmat=matobj.ROIs(1,1);
            if size(tempmat{1},2)==1
                disp('No ROIs selected')
                calc_rois=0;
            elseif isfield(tempmat{1}(1),'activity')
                disp('ROI activity already calculated');
                calc_rois=0;
            else
                calc_rois=1;
            end
        else
            if size(matobj.ROIs,2)==1
                disp('No ROIs selected')
                calc_rois=0;
            elseif isfield(matobj.ROIs(1,1),'activity')
                disp('ROI activity already calculated');
                calc_rois=0;
            else
                calc_rois=1;
            end
        end
    end
    %     if isempty(adata_file)
    %         calc_rois=0;
    %         display('Found no Adata file')
    %     else
    %         orig=load([adata_dir '\' userID '\' mouse_id '\' adata_file]);
    %         if iscell(orig.bv)
    %             tempmat=orig.ROIs(1,1);
    %             if size(tempmat{1},2)==1
    %                 disp('No ROIs selected')
    %                 calc_rois=0;
    %             elseif isfield(tempmat{1}(1),'activity')
    %                 disp('ROI activity already calculated');
    %                 calc_rois=0;
    %             else
    %                 calc_rois=1;
    %             end
    %         else
    %             if size(orig.ROIs,2)==1
    %                 disp('No ROIs selected')
    %                 calc_rois=0;
    %             elseif isfield(orig.ROIs(1,1),'activity')
    %                 disp('ROI activity already calculated');
    %                 calc_rois=0;
    %             else
    %                 calc_rois=1;
    %             end
    %         end
    %     end
    if calc_rois
        disp('**********************************');
        disp(['Now calculating ROI act of exp ' num2str(ExpIDs(ind))]);
        disp('**********************************');
        evalin('base','clear data');
        calc_act(ExpIDs(ind),adata_dir,dvh)
    end
end

function preview_adata_callback(e,h,ExpLog,dvh,adata_dir)
[~,ExpIDs,~,~]=get_menu_data(ExpLog,dvh,adata_dir);
[file_ID,mouse_ID,user_ID]=find_adata_file(ExpIDs(get(dvh.exp_select,'value')),adata_dir);
if isempty(file_ID)
    disp('No AData found');
else
    disp(['Previewing Adata of file ' file_ID])
    prev_adata=load([adata_dir user_ID '\' mouse_ID '\' file_ID]);
    assignin('base','prev_adata',prev_adata);
end

function [userIDs,ExpIDs,ExpStrs,same_site_as_ID,mouseIDs,ExpGroup,projectIDs,ftypes,...
    comments]=get_menu_data(ExpLog,dvh,adata_dir)

global adata_list_num;

ud=get(dvh.hf,'UserData');

userIDs=unique(ExpLog.pi, 'first');
user_ind=find(strcmp(ExpLog.pi,userIDs(get(dvh.user_select,'value'))));

projectIDs=unique(ExpLog.project(user_ind),'first');
project_ind=find(strcmp(ExpLog.project,projectIDs(get(dvh.project_select,'value'))));

mouseIDs = unique(ExpLog.animalid(project_ind),'first');
mouse_ind=find(strcmp(ExpLog.animalid,mouseIDs(get(dvh.mouse_select,'value'))));
% assignin('base','mouseIDs', mouseIDs);
% assignin('base','mouse_ind', mouse_ind);

[ExpIDs,ExpIDs_ind]=unique(cell2mat(ExpLog.expid(mouse_ind)),'first');
% assignin('base','ExpIDs', ExpIDs);
% assignin('base','ExpIDs_ind', ExpIDs_ind);

same_site_as_ID = ExpLog.siteid(mouse_ind);
same_site_as_ID = same_site_as_ID(ExpIDs_ind);
same_site_as_ID = cell2mat(same_site_as_ID);
% assignin('base','mysite', same_site_as_ID);

ExpStrs=[num2str(ExpIDs), char(ones(length(ExpIDs),1)*[32,45,32]), num2str(same_site_as_ID)];
ExpStrs=mat2cell(ExpStrs,ones(length(ExpIDs),1));
% assignin('base','ExpStrs', ExpStrs);

mouse_IDs=ExpLog.comment(mouse_ind);

curr_exp_sel_ind=get(dvh.exp_select,'value');
if curr_exp_sel_ind>length(same_site_as_ID)
    curr_exp_sel_ind=1;
end
ExpLog.siteid = cell2mat(ExpLog.siteid);
ExpLog.expid = cell2mat(ExpLog.expid);

ExpGroup = [same_site_as_ID(curr_exp_sel_ind); ExpLog.expid(ExpLog.siteid == same_site_as_ID(curr_exp_sel_ind))];
% assignin('base','ExpGroup', ExpGroup);
% assignin('base','mouse_IDs', mouse_IDs);

[~,b,~]=unique(ExpGroup,'first');
ExpGroup=ExpGroup(sort(b));

for ind=1:length(ExpIDs)
    if sum(adata_list_num()==ExpIDs(ind))
        ExpStrs{ind}=['A. ' ExpStrs{ind} ' - ' mouse_IDs{ExpIDs_ind(ind)}];
    else
        ExpStrs{ind}=[ExpStrs{ind} ' - ' mouse_IDs{ExpIDs_ind(ind)}];
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% myfile=[ud.rdataclea_dir userIDs{get(dvh.user_select,'value')} '\' mouseIDs{get(dvh.mouse_select,'value')} '\']
curr_files=dir([ud.rdata_dir userIDs{get(dvh.user_select,'value')} '\' mouseIDs{get(dvh.mouse_select,'value')} '\']);
tmp3 = regexp(sprintf('%i ',ExpIDs),'(\d+)','match'); % faster than num2str individually in the 2nd for loop
curr_files={curr_files.name}.';
for ind=1:length(ExpIDs)
    %     cnt=0;
    %     for knd=1:length(curr_files)
    %         if ~isempty(strfind(curr_files(knd).name,tmp3{ind}))
    %             cnt=cnt+1;
    %             ftypes{ind}{cnt}=curr_files(knd).name(end-3:end);
    %         end
    %     end
    jnd = cellfun(@(x)(~isempty(x)),regexp(curr_files,tmp3(ind)))';
    ftypes{ind}= cellfun(@(x)regexp(x, '\.\w+', 'match'), curr_files(jnd), 'UniformOutput', true);
end

if ~exist('ftypes','var')
    for ind=1:length(ExpIDs)
        ftypes{ind}='no data';
    end
end

[~,~,comment_ID]=unique(ExpLog.expid(mouse_ind));
for ind=1:length(ExpIDs)
    comments{ind}=mouse_IDs(comment_ID==ind);
end



function [ExpIDs]=get_proj_ExpIDs(ExpLog,dvh)

[userIDs]=get(dvh.user_select,'string');
user_ind=find(strcmp(ExpLog.pi,userIDs(get(dvh.user_select,'value'))));

[projectIDs]=get(dvh.project_select,'string');
project_ind=find(strcmp(ExpLog.project,projectIDs(get(dvh.project_select,'value'))));

project_ind=intersect(user_ind,project_ind);

ExpIDs=unique(cell2mat(ExpLog.expid(project_ind)),'first');


% col = find(strcmp(xls_txt(1,:), 'Project') == 1);
% [projectIDs]=unique(xls_txt(2:end,col),'first');
% project_ind=find(strcmp(xls_txt(2:end,col),projectIDs(get(dvh.project_select,'value'))));
% ExpIDs=unique(xls_num(project_ind,2),'first');




